package dp.mobile.eden;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import dp.mobile.comm.worker.BluetoothHandler;
import dp.mobile.system.SoundManager;
import dp.mobile.system.Utilities;

public class MainMenuAct extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		initComp();
		setListener();
		
		SoundManager.instance(getBaseContext()).playBGM(Utilities.BGM_FOLDER + "/title.mp3", true);
		//SoundManager.instance(getBaseContext()).playSFX(Utilities.SFX_FOLDER + "/build.wav");
	}
	
	private void initComp(){
		mContinueBtn		= (Button) findViewById(R.id.continue_btn);
		mDownloadLevelBtn	= (Button) findViewById(R.id.download_level_btn);
		mCampaignBtn		= (Button) findViewById(R.id.campaign_btn);
		mSkirmishBtn		= (Button) findViewById(R.id.skirmish_btn);
		mMultiplayerBtn		= (Button) findViewById(R.id.multiplayer_btn);
		mHighscoreBtn		= (Button) findViewById(R.id.highscore_btn);
		mOptionBtn			= (Button) findViewById(R.id.option_btn);
		
		//mDownloadLevelBtn.setVisibility(View.GONE);
	}
	
	private void setListener(){
		mCampaignBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				startActivity(new Intent(MainMenuAct.this.getApplicationContext(), CampaignLevelSelectAct.class));	
			}
		});
		
		mDownloadLevelBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent tIntent = new Intent(MainMenuAct.this.getApplicationContext(), SkirmishLevelSelectAct.class);
				tIntent.putExtra(SKIRMISH_EXTRA, DOWNLOAD_LEVEL_INTENT);
				startActivity(tIntent);
			}
		});
		
		mSkirmishBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent1 = new Intent(MainMenuAct.this.getApplicationContext(), SkirmishLevelSelectAct.class);
				intent1.putExtra(SKIRMISH_EXTRA, SELECT_LEVEL_INTENT);
				startActivity(intent1);	
			}
		});
		
		mMultiplayerBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				startActivity(new Intent(MainMenuAct.this.getApplicationContext(), InitiateMultiplayerAct.class));	
			}
		});
		
		mOptionBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				startActivity(new Intent(MainMenuAct.this.getApplicationContext(), OptionAct.class));
			}
		});
		
		mHighscoreBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				/*Intent intent1 = new Intent(MainMenuAct.this.getApplicationContext(), SkirmishLevelSelectAct.class);
				intent1.putExtra(SKIRMISH_EXTRA, HIGH_SCORE_INTENT);
				startActivity(intent1);*/
				
				Intent intent1 = new Intent(MainMenuAct.this.getApplicationContext(), HighScoreAct.class);
				startActivity(intent1);
				
				/*Intent intent1 = new Intent(MainMenuAct.this.getApplicationContext(), TwitterAct.class);
				intent1.putExtra(GameActivityBase.LEVEL_EXTRAS, "Level Ganteng");
				intent1.putExtra(GameActivityBase.SCORE_EXTRAS, 583);
				startActivity(intent1);*/
				
				//startActivity(new Intent(MainMenuAct.this.getApplicationContext(), TwitterAct.class));
				
				/*Intent intent1 = new Intent(MainMenuAct.this.getApplicationContext(), FacebookAct.class);
				intent1.putExtra(GameActivityBase.LEVEL_EXTRAS, "Level One");
				intent1.putExtra(GameActivityBase.SCORE_EXTRAS, 750);
				startActivity(intent1);*/
				
				//startActivity(new Intent(MainMenuAct.this.getApplicationContext(), PauseAct.class));
			}
		});
		
		mContinueBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent i = new Intent(MainMenuAct.this.getApplicationContext(), CampaignAct.class);
				i.putExtra(CampaignAct.EXTRA_CONTINUE, true);
				startActivity(i);	
			}
		});
		
		mContinueBtn.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				return false;
			}
		});
	}

	@Override
	protected void onPause() {
		super.onPause();
		SoundManager.instance(getBaseContext()).temporarySetMute(true);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		SoundManager.instance(getBaseContext()).temporarySetMute(false);
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		BluetoothHandler.getInstance().finish();
	}
	
	@Override
	public void onBackPressed() {
		super.onBackPressed();
		SoundManager.instance(getBaseContext()).stopAllSound();
		SoundManager.instance(getBaseContext()).releasePool();
	}
	
	//PROPERTIES
	private Button mContinueBtn, mDownloadLevelBtn, mCampaignBtn, mMultiplayerBtn, mHighscoreBtn, mOptionBtn, mSkirmishBtn;
	
	public static final String SKIRMISH_EXTRA = "PLAY_OR_HIGH_SCORE";
	public static final int SELECT_LEVEL_INTENT = 0;
	public static final int DOWNLOAD_LEVEL_INTENT = 1;
}
